package com.douqu.game.core.entity.world.map;

import com.douqu.game.core.entity.EntityObject;
import com.douqu.game.core.entity.battle.BattleTemp;
import com.douqu.game.core.entity.battle.SpriteTemp;
import com.douqu.game.core.util.LogUtils;


/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-05-30 11:48
 */
public class RecoverParam extends EntityObject {

    private int masterBaseHPRate;

    private int masterAddHPRate;

    private int armyBaseHPRate;

    private int armyAddHPRate;

    /**
     * 加多少次
     */
    private int count;


    public RecoverParam(BattleTemp battleTemp, int count)
    {
        this.count = count;

        masterBaseHPRate = battleTemp.getMasterHPRate();
        masterAddHPRate = (int) ((100 - masterBaseHPRate) * ((double)1/count));

        armyBaseHPRate = battleTemp.getArmyHPRate();
        armyAddHPRate = (int) ((100 - armyBaseHPRate) * ((double)1/count));

        LogUtils.debug("设置恢复数据 -> " + this);
        LogUtils.debug("battleTemp -> " + battleTemp);
    }


    public void onceRecover(BattleTemp battleTemp)
    {
        count--;

        if(!battleTemp.getMaster().isMax())
        {
            if(count <= 0)
                battleTemp.getMaster().full();
            else
                battleTemp.getMaster().addHPByRate(masterAddHPRate*0.01);
        }

        double armyRate = armyAddHPRate*0.01;
        for(SpriteTemp spriteTemp : battleTemp.getSoldierList())
        {
            if(spriteTemp.isMax())
                continue;

            if(count <= 0)
                spriteTemp.full();
            else
                spriteTemp.addHPByRate(armyRate);
        }

        LogUtils.debug("单次恢复HP battleTemp -> " + battleTemp);
    }

    public int getCount() {
        return count;
    }

    @Override
    public String toString() {
        return "{" +
                "masterBaseHPRate=" + masterBaseHPRate +
                ", masterAddHPRate=" + masterAddHPRate +
                ", armyBaseHPRate=" + armyBaseHPRate +
                ", armyAddHPRate=" + armyAddHPRate +
                ", count=" + count +
                "} ";
    }
}
